public class Day8 {
    public static void main(String[] args) {
        //int[][] arr = {{1,1,1},{1,1,0},{1,0,1}};
        int[][] arr = {{0,0,0},{0,0,0}};
        floodFill(arr,1,0,2);
    }
    //733.图形渲染
    static int n;
    static int x;
    public static int[][] floodFill(int[][] image, int sr, int sc, int color) {
        if(color == image[sr][sc]) return image;
        n=color;
        x=image[sr][sc];
        dfs(image,sr,sc);
        return image;
    }
    public static void dfs(int[][] image,int i,int j) {
        //上、下、左、右
        image[i][j] = n;//先修改原始值
        if(i-1>=0 && image[i-1][j]==x) {

            dfs(image,i-1,j);
        }
        if(i+1<image.length&& image[i+1][j]==x) {
            //image[i][j] = n;
            dfs(image,i+1,j);
        }
        if(j-1>=0 && image[i][j-1]==x) {
            //image[i][j] = n;
            dfs(image,i,j-1);
        }
        if(j+1<image[0].length && image[i][j+1]==x) {
            //image[i][j] = n;
            dfs(image,i,j+1);
        }
    }
}
